package com.eco.fanliapp.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.eco.fanliapp.common.response.ServerResponse;
import com.eco.fanliapp.dao.CommissionSchemeMapper;
import com.eco.fanliapp.entity.CommissionScheme;
import com.eco.fanliapp.service.ICommissionSchemeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CommissionSchemeServiceImpl extends ServiceImpl<CommissionSchemeMapper, CommissionScheme> implements ICommissionSchemeService {

    @Autowired
    private CommissionSchemeMapper commissionSchemeMapper ;
    /**
     *  动态字段,写入数据库记录,web_commission_scheme
     *
     * @param commissionScheme
     */
    @Override
    public ServerResponse insertSelective(CommissionScheme commissionScheme) {

        Integer id = commissionScheme.getId();
        if (id == null){
            int insertSelective = commissionSchemeMapper.insertSelective(commissionScheme);
            if(insertSelective == 1){
                return ServerResponse.createBySuccessMessage("增加成功");
            }
            return ServerResponse.createByErrorMessage("增加失败");
        }
        int update = commissionSchemeMapper.updateByPrimaryKeySelective(commissionScheme);
        if (update ==1){

            return ServerResponse.createBySuccessMessage("更改成功");
        }
        return ServerResponse.createByErrorMessage("更改失败");

    }
    /**
     *  动态字段,根据主键来更新符合条件的数据库记录,web_commission_scheme
     *
     * @param commissionScheme
     */
    @Override
    public ServerResponse updateByPrimaryKeySelective(CommissionScheme commissionScheme) {
        int update = commissionSchemeMapper.updateByPrimaryKeySelective(commissionScheme);
        if (update ==1){

            return ServerResponse.createBySuccessMessage("更改成功");
        }
        return ServerResponse.createByErrorMessage("更改失败");
    }


}
